<extend name="Base/common" />
<block name="body">
	<!--导航引用-->
	<header class="ui-header ui-header-stable ui-border-b">
	    <i class="icon-return iconfont icon-back" onclick="javascript:history.go(-1);"></i>
	    <h1>收货地址</h1>
	    <button class="ui-btn web_index add_ress">新增</button>
	</header>
	<footer class="ui-footer ui-footer-stable ui-btn-group ui-whitespace ui-border-t">
		<input type="hidden" value="{$data.order_type}" id="order_type">
	    <a href="#" class="ui-btn-lg ui-btn-danger sureDefault">确定</a>
	</footer>
	<section class="ui-container">
		<empty name="list">
			您还未设置收货地址哦
		<else />
			<ul class="ui-user-address-list">
				<volist name="list" id="v">
					<li class="<eq name='v.default' value='1'>selected</eq> ui-border-tb user_address_{$v.id}" did="{$v.id}">
						<div class="ui-address-info">
							<div class="ui-user-info">
								<b>{$v.name}</b>
								<span>{$v.phone}</span>
							</div>
							<p class="ui-user-address"><eq name="v.default" value="1"><b>[默认]</b></eq>
							{$v.pro_id|getAreaName=###} {$v.city_id|getAreaName=###} {$v.area_id|getAreaName=###} {$v.address}</p>
						</div>
						<div class="ui-address-btn-wrap ui-border-t ui-flex-pack-end">
					        <div class="ui-btn-group">
								<a href="{:U('edit_address', array('id' => $v['id'], 'order_type' => $data['order_type']))}">
									<i class="iconfont icon-edit"></i>
									<span>编辑</span> 
								</a>
								<a href="javascript::" class="del" did="{$v.id}">
									<i class="iconfont icon-delete"></i>
									<span>删除</span>
								</a>
							</div>
						</div>
					</li>
				</volist>
			</ul>
		</empty>
	</section>
</block>
<block name="script">
	<script type="text/javascript">
		$('.del').tap(function(){
			var obj = $(this);
			var dia=$.dialog({
		        title:'温馨提示',
		        content:'是否确定删除该商品？',
		        button:["确认","取消"]
		    });
		    dia.on("dialog:action",function(e){
		    	if(e.index == 0){
		    		var id = Number(obj.attr('did'));
					$.get("{:U('del_address')}", {id: id}, function(r){
						if(r.status){
							$.tips({
						        content:'删除成功！',
						        stayTime:2000,
						        type:"success"
						    });
						    $('.user_address_' + id).remove();
						}else{
							$.tips({
						        content:'删除失败！',
						        stayTime:2000,
						        type:"success"
						    });
						}
					}, 'json');
		    	}
		    });
			
		});
		//新增
		$('.add_ress').tap(function(){
			window.location.href = "{:U('add_address', array('order_type' => $data['order_type']))}";
		});
		//选择
		var temp_id = 0;
		$('.ui-user-address-list li').tap(function(){
			temp_id = $(this).attr('did');
			$(this).addClass('selected').siblings().removeClass('selected');
		});
		//确定操作
		$('.sureDefault').tap(function(){
			if(temp_id == 0){
				temp_id = $('.ui-user-address-list .selected').attr('did');
			}
			var order_type = $('#order_type').val();
			$.get("{:U('updateDefault')}", {id: temp_id, order_type: $('#order_type').val()}, function(r){
				if(r.status){
					if( order_type == 'yes' ){
						window.location.href = r.url;
					}else{
						$.tips({content:'修改成功！',stayTime:2000,type:"success"});
					}
				}else{
					$.tips({content:'修改失败',stayTime:2000,type:"success"});
				}
			}, 'json');
		});
	</script>
</block>